<template>
  <su-popup
    :show="show"
    type="bottom"
    round="20"
    @close="emits('close')"
    showClose
    backgroundColor="#000"
  >
    <view class="model-box">
      <view class="title ss-m-t-16 ss-m-l-20 ss-flex ss-row-center">实付金额（积分）</view>
      <view class="number">1500.00</view>
      <view class="form">
        <view class="balance  ss-flex ss-col-center ss-row-between">
          <view class="balance-l ss-flex">
            <image class="balance-1" src="@/static/img/payMethod-1.png"></image>
            <view>余额支付</view>
          </view>
          <view class="balance-r">
            可用：￥200000
            <radio
              @tap="state.payment='payMethod1'"
              :value="state.payment"
              color="#14c194"
              style="transform: scale(0.8)"
              :checked="state.payment === 'payMethod1'"
            />
          </view>
        </view>
        <view class="balance  ss-flex ss-col-center ss-row-between">
          <view class="balance-l ss-flex">
            <image class="balance-1" src="@/static/img/payMethod-2.png"></image>
            <view>红包支付</view>
          </view>
          <view class="balance-r">
            可用：￥200000
              <radio
                @tap="state.payment='payMethod2'"
                :value="state.payment"
                color="#14c194"
                style="transform: scale(0.8)"
                :checked="state.payment === 'payMethod2'"
              />
          </view>
        </view>
      </view>
      <uni-forms
        ref="payRef"
        v-model="state.model"
        :rules="state.rules"
        validateTrigger="bind"
        labelWidth="140"
        labelAlign="center"
      >
        <uni-forms-item name="code" label="支付密码">
          <uni-easyinput placeholder="请输入支付密码" v-model="state.model.password" :inputBorder="false">
            <template v-slot:right>
              <button class="ss-reset-button ">
                去设置支付密码
              </button>
            </template>
          </uni-easyinput>
        </uni-forms-item>
      </uni-forms>
    </view>
    <view class="modal-footer ss-flex">
      <button class="confirm-btn " @tap="onConfirm">立即支付</button>
    </view>
  </su-popup>
</template>
<script setup>
  import { computed, reactive, ref, unref } from 'vue';
  import { code } from '@/sheep/validate/form';
  import sheep from '@/sheep';

  const props = defineProps({
    modelValue: {
      type: Object,
      default() {
      },
    },
    show: {
      type: Boolean,
      default: true,
    },
  });
  const emits = defineEmits(['confirm', 'close']);
  const state = reactive({
    couponInfo: computed(() => props.modelValue),
    couponId: 0,
    payment: null,
    model: {
      password: '', // 密码
    },
    rules: {
      code,
    },
  });
  const payRef = ref(null);



  function radioChange(couponId) {
    if (state.couponId == couponId) {
      state.couponId = 0;
    } else {
      state.couponId = couponId;
    }
  }

  const onConfirm = async () => {
    const validate = await unref(payRef)
      .validate()
      .catch((error) => {
        console.log('error: ', error);
      });
    if (!validate) return;
    emits('confirm', state.couponId);
  };
</script>
<style lang="scss" scoped>
  :deep() {
    .uni-radio-input {
      background-color: transparent;
    }

    .uni-forms-item {
      padding: 0 15px;
      box-sizing: border-box;
      height: 50px;
      background: #1E1E1E;
      border-radius: 10px;
      width: 345px;
      margin: 10px auto 0;
      .ss-reset-button {
        color: #00A1FF;
      }
    }

    .uni-forms-item__label {
      .label-text {

        font-weight: 400;
        font-size: 15px;
        color: #FFFFFF
      }

      height: 100%;
    }

    .uni-forms-item__box, .uni-forms-item__inner, .uni-easyinput, .uni-easyinput__content {
      height: 100%;
    }

    .uni-forms-item__inner {
      padding-bottom: 5px;
    }

    .uni-input-input {
      color: #fff;
    }
  }

  .model-box {
  }

  .title {
    height: 80rpx;
    font-weight: 400;
    font-size: 16px;
    color: #A6A6A6;
  }

  .number {
    font-weight: 500;
    font-size: 36px;
    line-height: 36px;
    color: #F5F6F8;
    padding: 27px 0;
    text-align: center;
  }

  .form {
    width: 345px;
    background: #1E1E1E;
    border-radius: 10px;
    box-sizing: border-box;
    margin: 0 auto;

    .balance {
      padding: 18px 15px;
      box-sizing: border-box;

      &:first-child {
        border-bottom: 1px solid #353535;
      }

      .balance-l {
        .balance-1 {
          width: 15px;
          height: 15px;
          margin-right: 8px;
        }

        font-weight: 400;
        font-size: 15px;
        color: #FFFFFF;
      }

      .balance-r {
        font-weight: 400;
        font-size: 15px;
        color: #FFFFFF;
      }
    }



  }

  .subtitle {
    font-size: 26rpx;
    font-weight: 500;
    color: #333333;
  }

  .model-content {
    height: 54vh;
  }

  .modal-footer {
    width: 100%;
    padding: 16px 15px;
    box-sizing: border-box;
  }

  .confirm-btn {
    width: 100%;
    height: 50px;
    line-height: 50px;
    font-weight: 500;
    font-size: 16px;
    color: #090909;
    background: linear-gradient(90deg, #45C9F0, #36F6AF);
    border-radius: 25px;
  }

</style>
